package com.cskaoyan.service.impl;

import com.cskaoyan.mapper.GoodsMapper;
import com.cskaoyan.mapper.GoodsProductMapper;
import com.cskaoyan.mapper.OrderGoodsMapper;
import com.cskaoyan.mapper.UserMapper;
import com.cskaoyan.model.GoodsExample;
import com.cskaoyan.model.GoodsProductExample;
import com.cskaoyan.model.OrderGoodsExample;
import com.cskaoyan.model.UserExample;
import com.cskaoyan.model.vo.TotalV0;
import com.cskaoyan.service.DashboardService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

/**
 * @author ：huzhouming
 * @description：实现首页所需要的功能
 * @date ：2022/5/5 19:55
 */
@Service
public class DashboardServiceImpl implements DashboardService {
    @Autowired
    UserMapper userMapper;
    @Autowired
    GoodsMapper goodsMapper;
    @Autowired
    GoodsProductMapper goodsProductMapper;
    @Autowired
    OrderGoodsMapper orderGoodsMapper;

    @Transactional
    @Override
    /**
     * @author: huzhouming
     * @description: 获取首页所需要的各种总数量
     * @date: 2022/5/5
     * @param
     * @return com.cskaoyan.model.vo.TotalV0
     */
    public TotalV0 getDataTotal() {
        long userTotal = userMapper.countByExample(new UserExample());
        long goodsTotal = goodsMapper.countByExample(new GoodsExample());
        long goodsProductTotal = goodsProductMapper.countByExample(new GoodsProductExample());
        long orderGoodsTotal = orderGoodsMapper.countByExample(new OrderGoodsExample());
        TotalV0 totalV0 = new TotalV0();
        totalV0.setUserTotal((int) userTotal);
        totalV0.setGoodsTotal((int)goodsTotal);
        totalV0.setOrderTotal((int)orderGoodsTotal);
        totalV0.setProductTotal((int)goodsProductTotal);
        return totalV0;
    }
}
